//
//  CryptoApp.swift
//  Crypto
//
//  Created by DaleGuo on 2023/9/20.
//

import SwiftUI

@main
struct CryptoApp: App {
    // 从主函数入口创建StateObj，让所有视图都能使用到HomeViewModel
    @StateObject var vm = HomeViewModel()
    @State private var showLauchView: Bool = true

    init() {
        // 覆盖所有的NavigationTitle,修改字体颜色样式
        UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor(Color.theme.accent)]
        UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor(Color.theme.accent)]
    }

    var body: some Scene {
        WindowGroup {
            ZStack {
                NavigationStack {
                    HomeView()
                        .toolbar(.hidden)
                }
                .environmentObject(vm) // 所有子view都能使用到vm

                ZStack {
                    if showLauchView {
                        LaunchView(showLaunchView: $showLauchView)
                            .transition(.move(edge: .leading))
                    }
                }
                .zIndex(2.0)
            }
        }
    }
}
